package com.zmzncs.lmtc.module.order.controller;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JwtUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.customer.service.MonthRecordService;
import com.zmzncs.lmtc.module.order.pojo.order_Info.IncomeVO;
import com.zmzncs.lmtc.module.order.pojo.order_Info.OrderInfoDTO;
import com.zmzncs.lmtc.module.order.pojo.order_Info.OrderInfoManageVO;
import com.zmzncs.lmtc.module.order.pojo.order_Info.ParkOrderInfoVO;
import com.zmzncs.lmtc.module.order.service.OrderInfoService;
import com.zmzncs.lmtc.module.order.service.ParkReserveRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * @author 高博文
 * @since 2020-09-01
 */
@Api(tags = "订单")
@RestController
@RequestMapping("/order/orderInfo")
@Slf4j
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;
    @Autowired
    MonthRecordService monthRecordService;
    @Autowired
    private ParkReserveRecordService parkReserveRecordService;

    @ApiOperation(value = "首页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType = "query",name = "parkId", value = "车场ID", required = false),
    })
    @GetMapping(value = "getParkingOwnerData")
    public Rest<OrderInfoManageVO> getParkingOwnerData(Long parkId) {
        OrderInfoManageVO ownerData = orderInfoService.getParkingOwnerData(parkId);
        return RestUtil.success(ownerData);
    }


    @ApiOperation(value = "业务-车场管理")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType = "query",name = "parkId", value = "车场ID", required = true),
            @ApiImplicitParam(paramType = "query",name = "selectDate", value = "查询时间", required = true),
            @ApiImplicitParam(paramType="query", name = "currentPage", value = "页码", required = true),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true),
    })
    @GetMapping(value = "getParkOrderInfo")
    public Rest<ParkOrderInfoVO> getParkOrderInfo(@NotNull Long parkId, @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd") Date selectDate,@NotNull Integer currentPage, @NotNull Integer pageSize) {
        ParkOrderInfoVO parkOrderInfoVO = orderInfoService.getParkOrderInfo(parkId,selectDate,currentPage,pageSize);
        return RestUtil.success(parkOrderInfoVO);
    }

    @ApiOperation(value = "昨天、今天、本周、本月的缴费")
    @ApiImplicitParams({
            @ApiImplicitParam(name="dateType", value="时间类型（1：昨天、2：今天、3：本周、4：本月，5：本年）"),
    })
    @GetMapping("get-paid-amount-by-date")
    public Rest<String> getPaidAmountByDate(@RequestParam Long parkId, @RequestParam Integer dateType) {
        String paidAmountByDate = orderInfoService.getPaidAmountByDate(parkId, dateType);

        return RestUtil.success(paidAmountByDate);
    }

    @ApiOperation(value = "每月收益")
    @ApiImplicitParams({
            @ApiImplicitParam(name="parkId", value="停车场id"),
    })
    @GetMapping("get-month-income")
    public Rest<Map> getMonthIncome(@RequestParam Long parkId) {
        Map monthIncome = orderInfoService.getMonthIncome(parkId);

        return RestUtil.success(monthIncome);
    }

    @ApiOperation(value = "预约、泊车、月租总收益环比")
    @ApiImplicitParams({
            @ApiImplicitParam(name="parkId", value="停车场id"),
    })
    @GetMapping("income")
    public Rest<IncomeVO> income(@RequestParam Long parkId) {
        Map income = orderInfoService.income(parkId);

        return RestUtil.success(income);
    }

    @ApiOperation(value = "今日收益")
    @ApiImplicitParams({
            @ApiImplicitParam(name="parkId", value="停车场id"),
    })
    @GetMapping("income-today")
    public Rest<String> incomeToday(@RequestParam Long parkId) {
        //  泊车收益
        String parkIncome = orderInfoService.getPaidAmountByDate(parkId, 2);
        //  月租收益
        String monthlyRentIncome = monthRecordService.getMonthRecordAmountByDate(parkId, 2);
        //  预约收益
        String reserveIncome = parkReserveRecordService.getReserveAmountByDate(parkId, 2);


        return RestUtil.success(new BigDecimal(parkIncome).add(new BigDecimal(monthlyRentIncome)).add(new BigDecimal(reserveIncome)));
    }

}

